/**
* @Description: WoShop商城
* @Author: 梧桐
* @Copyright: 武汉一一零七科技有限公司©版权所有
* @Link: www.wo-shop.net
* @Contact: QQ:2487937004
*/
<template>
	<view>
		<u-swiper class="swiperBox" :list="bannerList" name="ad_pic" @click="bannerClick" height="240" :border-radius="0"></u-swiper>
		<u-sticky>
			<div class="u-flex timeScroll u-col-center">
				<u-image class="iconSpike" :src="spikeIconSrc" width="74" height="82" mode="widthFix"></u-image>
				<scroll-view class="scroll-view_H u-flex" scroll-x="true" scroll-with-animation="true"
					:scroll-into-view="'active'+toId">
					<view class="scrollItem" :id="'active' + index" :class="[activeClass == index ? 'active' : '' ]"
						v-for="(timeList,index) in limitList" :key="index" @click="clickTime(timeList.time)">
						<view class="scrollItemTime" :class="{active: activeClass == index}">{{timeList.time }}</view>
						<view class="scrollItemStatus" :class="{active: activeClass == index}">
							{{ timeList.cuxiao == 0?$t('即将开始'):$t('抢购中') }}</view>
					</view>
				</scroll-view>
			</div>
		</u-sticky>

		<view class="spike-content">
			<view class="spike-time u-flex u-row-between" style="padding: 0 20rpx" v-if="cuxiao == 0">
				<view>{{$t('限时限量，好货低价')}}</view>
				<view>{{$t('剩余时间')}}
					<uni-countdown @timeuptime="timeuptime" color="#FFFFFF" background-color="#FF6262"
						border-color="#FF6262" :day="0" :hour="countDown.hour" :minute="countDown.minute"
						:second="countDown.second" :show-day="false" :show-colon="false">
					</uni-countdown>
				</view>
			</view>
			<view class="spike-time u-flex u-row-between" style="padding: 0 20rpx" v-if="show == 1">
				<view>{{$t('限时限量，好货低价')}}
					<uni-countdown @timeuptime="timeuptime" color="#FFFFFF" background-color="#FF6262"
						border-color="#FF6262" :day="0" :hour="countDown.hour" :minute="countDown.minute"
						:second="countDown.second" :show-day="false" :show-colon="false">
					</uni-countdown>
				</view>
			</view>
			<view class="goodsCard" :class="{'greenColor': cuxiao===0}" v-for="(goods,index) in goodres" :key="index">
				<view class="u-flex" @click.stop="settes(goods.goods_id,goods.id)">
					<u-image width="220" height="220" style="flex-shrink: 0;margin-right:20rpx" border-radius="18"
						:src="goods.thumb_url" />
					<view class="goodsCardRight">
						<p class="u-line-2 goodsName">{{goods.goods_name}}</p>
						<u-tag :text="$t('促销')" type="warning" shape="circle" plain size="mini" />
						<view class="u-flex u-row-between u-col-center" style="width:100%">
							<view class="priceBox">
								<div class="u-flex" style="align-items: flex-end">
									<span class="priceBox1">¥{{goods.seckill_price}}</span>
									<span class="priceBox2">¥{{goods.shop_price}}</span>
								</div>
								<p class="lowerTips" v-if="false">{{$u.random(1, 105)}}{{$t('天最低价格')}}</p>
							</view>
							<view class="buyBtn" :class="{remind:cuxiao===0}">
								<span class="buyBtntxt1">
									<text v-if="cuxiao!=0">{{$t('抢购中')}}</text>
									<text v-if="cuxiao==0">{{$t('即将开始')}}</text>
								</span>
								<view class="buyBtntxt2" v-if="cuxiao!=0">
									<u-line-progress :percent="goods.sales_ratio" :round="false" :show-percent="false"
										height="10" active-color="#fff" inactive-color="rgba(255,255,255,0.3)">
									</u-line-progress>
								</view>
							</view>

						</view>
					</view>
				</view>
			</view>


			<loadMore :loadingType="loadingType"></loadMore>
		</view>

	</view>
</template>

<script>
	import uniCountdown from "../components/uni-countdown.vue";

	let dataObj = {
		nowtime: '',
		page: 1
	}
	export default {
		data() {
			return {
				bannerList: [],
				limitList: [],
				scrollLeft: 0,
				toId: '',
				countDown: {
					hour: 0,
					minute: 0,
					second: 10
				},
				goodres: [], // 商品列表
				loadingType: 0,
				cuxiao: 0, //0即将开始  1以开始
				limitdeIndex: 0,
				show: 0,
				lowerTime: 12,
				spikeIconSrc: '',
				activeClass: 0
			}
		},
		onLoad() {
			this.spikeIconSrc = this.STATICURL + 'images/activity/icon-spikeIcon2.png'
			this.getBannerList()
		},
		onShow() {
			if (!this.goodres.length) {
				dataObj.page = 1
				this.loadingType = 0
				this.goodres = []
				this.getSeckillTime()
			}


		},
		onReachBottom: function() {
			// 上拉加载更多
			if (this.loadingType == 1 || this.loadingType == 2) {
				return false
			}
			this.loadingType = 1

			dataObj.page++
			this.getActivity(dataObj)
		},
		watch: {

		},

		methods: {
			btnClick() {

			},
			getBannerList(){
				const data = {
					tag: 'mobile_seckill_banner'
				}
				this.$http.getAdByTag(data).then(res => {
					if(res.status == 200){
						this.bannerList = res.data
					}
				})
			},
			bannerClick(index){
				let ad = this.bannerList[index];
				if(ad.ad_url != ''){
					this.$u.route({url:ad.ad_url,type:ad.ad_url_type})
				}
			},
			settes(id, id2) {
				console.log(this.cuxiao)
				if (this.cuxiao === 0) {
					this.getnav('/pagesC/homeSon/spike_details?id=' + id + '&rush_id=' + id2)
				} else {
					this.getnav('/pagesC/goods/goodsDetails?id=' + id + '&rush_id=' + id2)
				}
			},
			/**
			 * 点击选中时间段
			 */
			clickTime(time) {
				this.limitList.forEach((el, index) => {
					el.show = 0
					if (time == el.time) {
						this.limitdeIndex = 0
						el.show = 1
						this.toId = index
						dataObj.timeDate = el.countTime
						dataObj.page = 1
						this.loadingType = 0
						this.goodres = []
						this.$loading()
						this.getActivity(dataObj)
						this.activeClass = index
					}

				})
			},
			getSeckillTime() {
				this.$http.getSeckillTime().then(res => {
					if (res.status == 200) {

						for (var i = 0; i < res.data.length; i++) {
							let element = res.data[i]
							const date = new Date(element.time * 1000)
							const day = date.getDate()
							const getHours = date.getHours() > 9 ? date.getHours() : '0' + date.getHours()
							element.countTime = element.time
							if (element.show == 1) {
								this.toId = i
								dataObj.timeDate = element.time
								this.getActivity(dataObj)
							}
							element.time = `${getHours}:00`
						}
						this.limitList = res.data

					}
				})
			},
			getActivity(data) {
				this.$http.getActivity({
					nowtime: data.timeDate,
					page: data.page
				}).then(res => {
					if (res.status == 200) {
						console.log(res)
						this.cuxiao = res.data.cuxiao
						this.show = res.data.show
						if (Number(res.data.hdtime) > Number(res.data.dqtime)) {
							let str = Number(res.data.hdtime) - Number(res.data.dqtime)
							let strArr = this.$formatSeconds(str).split('-')
							this.countDown = {
								hour: Number(strArr[0]),
								minute: Number(strArr[1]),
								second: Number(strArr[2])
							}
						} else if (Number(res.data.hdtime) <= Number(res.data.dqtime) && res.data.show == 1) {
							let str = Number(res.data.end_time) - Number(res.data.dqtime)
							let strArr = this.$formatSeconds(str).split('-')
							this.countDown = {
								hour: Number(strArr[0]),
								minute: Number(strArr[1]),
								second: Number(strArr[2])
							}
						}

						if (res.data.goodres.length == 0) {
							this.loadingType = 2
							return false
						}

						this.goodres = [...this.goodres, ...res.data.goodres]
						this.loadingType = 0

					}
				})
			},
			/**
			 * 倒计时结束
			 */
			timeuptime() {
				if (this.cuxiao == 0) {
					dataObj.page = 1
					this.loadingType = 0
					this.goodres = []
					this.getSeckillTime()
				}

			},
			limitdeClick(i) {
				this.limitdeIndex = i
				dataObj.timeDate = i
				dataObj.page = 1
				this.loadingType = 0
				this.goodres = []
				this.$loading()
				this.getActivity(dataObj)
			}
		},
		components: {
			uniCountdown
		}
	}
</script>

<style lang="scss" scoped>
	@import '~uview-ui/index.scss';
	page {
		background-color: #f5f5f5;
	}

	.scroll-view_H {
		overflow-x: scroll;
		white-space: nowrap;
	}

	.scrollItem {
		display: inline-block;
		font-weight: bolder;
		padding: 0 25rpx;
		text-align: center;

		&Time {
			font-size: 34rpx;

			&.active {
				color: #FD1B48;
			}
		}

		&Status {
			color: #999;
			font-weight: normal;
			font-size: 20rpx;

			&.active {
				color: #fff;
				background-image: linear-gradient(to right, #FD1B48, #FE420C);
				border-radius: 100px;
				padding: 0 8rpx;
			}
		}
	}

	.spike-content {
		margin-top: 20rpx;

	}

	.spikeHeader {
		background-image: linear-gradient(to right, #FD015A, #FE2827);
		padding: 30rpx 0 20rpx;
		padding-top: calc(var(--status-bar-height));
		text-align: center;
		position: fixed;
		top: 0;
		width: 100%;
		z-index: 99;

	}

	.timeScroll {
		background-color: #fff;

		.iconSpike {
			margin: 30rpx 20rpx 0;
		}
	}

	.goodsCard {
		margin: 20rpx;
		border-radius: 18rpx;
		background-color: #fff;
		padding: 12rpx;
		position: relative;

		&index {
			position: absolute;
			top: 20rpx;
			left: 20rpx;
			background-color: rgba(#000, 0.3);
			width: 40rpx;
			height: 40rpx;
			line-height: 40rpx;
			display: inline-block;
			z-index: 999;
			text-align: center;
			color: #fff;
			border-radius: 5rpx
		}

		.goodsName {
			font-size: 28rpx;
			font-weight: 800;
			color: #333
		}

		&Right {
			width: 62%;
			height: 220rpx;
			flex-direction: column;
			display: flex;
			align-items: flex-start;
			justify-content: space-between;

			.lowerTips {
				color: #999;
				font-size: 24rpx;
			}
		}

		.priceBox {
			align-items: baseline;

			&1 {
				font-size: 38rpx;
				color: #FD1B48;
				font-weight: bolder;
			}

			&2 {
				font-size: 24rpx;
				color: #999;
				margin-left: 6rpx;
				text-decoration: line-through;
			}
		}

		.buyBtn {
			padding: 12rpx 20rpx;
			background-image: linear-gradient(to right, #FD184F, #FE420C);
			color: #fff;
			text-align: center;
			font-size: 20rpx;
			border-radius: 8rpx;
			line-height: 28rpx;
			flex-shrink: 0;

			&.remind {
				background-image: linear-gradient(to right, #0abb20, #80f38e);
			}

			&txt1 {
				font-size: 30rpx;
				font-weight: 800;
			}

			&txt2 {
				font-size: 24rpx;

			}
		}
	}
</style>
